package com.ruoyi.web.controller.inspection;

import java.util.List;

import com.ruoyi.common.config.HeadNum;
import com.ruoyi.common.core.domain.Ajax2Result;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.framework.util.GetSessionValueUtil;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.inspection.domain.FzInspectionDian;
import com.ruoyi.inspection.service.IFzInspectionDianService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 巡检点Controller
 * 
 * @author ruoyi
 * @date 2020-03-13
 */
@Controller
@RequestMapping("/inspection/dian")
public class FzInspectionDianController extends BaseController
{
    private String prefix = "inspection/dian";

    @Autowired
    private IFzInspectionDianService fzInspectionDianService;

    @RequiresPermissions("inspection:dian:view")
    @GetMapping()
    public String dian()
    {
        return prefix + "/dian";
    }

    /**
     * 查询巡检点列表
     */
    @RequiresPermissions("inspection:dian:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(FzInspectionDian fzInspectionDian)
    {
        startPage();
        fzInspectionDian.setcId(GetSessionValueUtil.getCommunity());
        List<FzInspectionDian> list = fzInspectionDianService.selectFzInspectionDianList(fzInspectionDian);
        return getDataTable(list);
    }

    /**
     * 导出巡检点列表
     */
    @RequiresPermissions("inspection:dian:export")
    @Log(title = "巡检点", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FzInspectionDian fzInspectionDian)

    {  fzInspectionDian.setcId(GetSessionValueUtil.getCommunity());
        List<FzInspectionDian> list = fzInspectionDianService.selectFzInspectionDianList(fzInspectionDian);
        ExcelUtil<FzInspectionDian> util = new ExcelUtil<FzInspectionDian>(FzInspectionDian.class);
        return util.exportExcel(list, "dian");
    }

    /**
     * 新增巡检点
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存巡检点
     */
    @RequiresPermissions("inspection:dian:add")
    @Log(title = "巡检点", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FzInspectionDian fzInspectionDian)
    {   fzInspectionDian.setInspectionId(HeadNum.DIAN_HEAD+ DateUtils.getTimeMillis());
        fzInspectionDian.setcId(GetSessionValueUtil.getCommunity());
        fzInspectionDian.setCreateBy(ShiroUtils.getSysUser().getUserName());
        return toAjax(fzInspectionDianService.insertFzInspectionDian(fzInspectionDian));
    }

    /**
     * 修改巡检点
     */
    @GetMapping("/edit/{inspectionId}")
    public String edit(@PathVariable("inspectionId") String inspectionId, ModelMap mmap)
    {
        FzInspectionDian fzInspectionDian = fzInspectionDianService.selectFzInspectionDianById(inspectionId);
        mmap.put("fzInspectionDian", fzInspectionDian);
        return prefix + "/edit";
    }

    /**
     * 修改保存巡检点
     */
    @RequiresPermissions("inspection:dian:edit")
    @Log(title = "巡检点", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FzInspectionDian fzInspectionDian)
    {fzInspectionDian.setUpdateBy(ShiroUtils.getSysUser().getUserName());
        return toAjax(fzInspectionDianService.updateFzInspectionDian(fzInspectionDian));
    }

    /**
     * 删除巡检点
     */
    @RequiresPermissions("inspection:dian:remove")
    @Log(title = "巡检点", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(fzInspectionDianService.deleteFzInspectionDianByIds(ids));
    }




    //请求所有巡检点
    @PostMapping("/allDian")
    @ResponseBody
    public Ajax2Result allDian(){
        FzInspectionDian fzInspectionDian=new FzInspectionDian();
        fzInspectionDian.setcId(GetSessionValueUtil.getCommunity());
        List<FzInspectionDian> list = fzInspectionDianService.selectFzInspectionDianList(fzInspectionDian);
        return Ajax2Result.success(list);
    }


    @GetMapping("/editDian")
    public String editDian(ModelMap map, @RequestParam(name="along",required = false ) String yi, @RequestParam(name="latitude",required = false) String er)
    {
        map.put("yi",yi);
        map.put("er",er);
        return prefix + "/dianEdit";
    }


    @PostMapping("/listDian")
    @ResponseBody
    public TableDataInfo listDian(FzInspectionDian fzInspectionDian,@RequestParam("routeId")String routeId)
    {
        startPage();
        fzInspectionDian.setcId(GetSessionValueUtil.getCommunity());
        List<FzInspectionDian> list = fzInspectionDianService.selectFzInspectionDianListByRouteId(fzInspectionDian,routeId);
        return getDataTable(list);
    }
}
